// import { Page } from "@/types/storeModule"
import { assign } from 'lodash-es'

const state = {
  // 接口调用参数
  params: {
    page: {
      currentPage: 1,
      pageSize: 20,
      totalCount: 0,
      totalPage: 0,
      sortField: 'id',
      order: 'desc'
    },
    options: {}
  },
  roles: {}, // 权限
  apiName: 'userReg',
  privileges: ['user_reg_add', 'user_reg_export', 'user_reg_import'],
  // 列表data数据
  isLoading: false,
  tableData: [],
  searchData: [
    // 使用|分割 为了搜索范围查询
    {
      id: 'createTimeStart|createTimeEnd',
      name: '报名时间',
      type: 'date_range',
      hint: '报名时间',
      defaultValue: ''
    },
    {
      id: 'entity.processingStatus',
      name: '处理状态',
      type: 'select',
      hint: '处理状态',
      options: [
        {
          key: '1',
          value: '未处理'
        },
        {
          key: '2',
          value: '已处理'
        },
        {
          key: '3',
          value: '已建账号'
        },
        {
          key: '4',
          value: '重复报名'
        },
        {
          key: '5',
          value: '报名异常'
        }
      ]
    },
    {
      id: 'keyword',
      name: '机构、姓名、相关资料、备注说明',
      type: 'text',
      hint: '机构、姓名',
      defaultValue: ''
    },
  ],
  // 使用|分割为了格式化列表数据
  tableHeadList: [
    {
      label: '报名时间',
      prop: 'createTime'
    },
    {
      label: '机构',
      prop: 'orgName'
    },
    {
      label: '姓名',
      prop: 'regUsername',
    },
    {
      label: '邮箱',
      prop: 'loginname'
    },
    {
      label: '电话',
      prop: 'tel'
    },
    {
      label: '官网',
      prop: 'website'
    },
    {
      label: '相关资料',
      prop: 'introFiles'
    },
    {
      label: '备注说明',
      prop: 'registerSurvey'
    }
  ]
}

// getters
const getters = {}

// actions
const actions = {}

// mutations
const mutations = {
  // 更新页面搜索内容
  updateSearchData(state, payload: any[]) {
    state.searchData = payload
  },
  // 更新表格 loading 状态
  updateLoading(state, payload: boolean) {
    state.isLoading = payload
  },

  // 更新数据page
  updatePage(state, payload: any) {
    state.params.page = assign(state.params.page, payload)
  },

  // 更新数据Condition
  updateCondition(state, payload: any) {
    state.params.condition = cloneDeep(payload)
  },

  // 更新data数据
  updateTableData(state, payload: any[]) {
    state.tableData = payload
  },
  // 更新列表表头数据
  updateEditTableList(state, payload: any[]) {
    state.tableHeadList = payload
  },
  // 更新列表参数数据
  updateParams(state, payload: any) {
    state.params = Object.assign({}, state.params, payload)
  },
  // 更新权限
  updateRoles(state, payload: Record<string, boolean>) {
    state.roles = payload
  }
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
